/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

/**
 *
 * @author Promociones
 */
public class FrameManager {
    
    public static JDialog Frame=new JDialog();
    
    public static void FrameCreator(Component comp,String name) {
          Frame=new JDialog();
          if((name==null)||("".equals(name))){
            Frame.setTitle(comp.getName());
          }else{
            Frame.setTitle(name);
          }
          Frame.setIconImage(null);
          Frame.setBackground(Color.white);
          Frame.add(comp);
          Frame.setSize(600, 600);
          Frame.pack();
          Frame.setModal(true);
          Frame.show(true);
    }
    
    public static void centreWindow(Window frame) {
        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
        int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
        frame.setLocation(x, y);
        URL url;
        try {
            url = ClassLoader.getSystemResource("GUI/Images/Logo.png");
            Toolkit kit = Toolkit.getDefaultToolkit();
            Image img = kit.createImage(url);
            frame.setIconImage(img);
        } catch (Exception ex) {
            Logger.getLogger(FrameManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void NextFocus(KeyEvent evt, Component comp){
       if(evt.getKeyCode() == 10){
           comp.requestFocus();
       }
    }
    
    public static void FrameCreator(JDesktopPane Pane,JInternalFrame IFrame){
        try {
            Frame.add(IFrame);
            IFrame.setVisible(true);
            IFrame.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(FrameManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
}
